package com.esun.rabbit2.viewer;

import java.util.ArrayList;
import java.util.List;

import org.androidpn.client.Constants;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;

import android.app.ActivityGroup;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.esun.RabbitApplication;
import com.esun.config.Config;
import com.esun.config.DistributionChannels;
import com.esun.config.Language;
import com.esun.model.LoadingInfo;
import com.esun.model.UserInfo;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.rabbit2.communicaters.DeviceInfoCollectCommunicater;
import com.esun.rabbit2.viewer.mainact.HemaiCenterAgp;
import com.esun.rabbit2.viewer.mainact.LotteryHallAct;
import com.esun.rabbit2.viewer.mainact.LotteryInfoAct;
import com.esun.rabbit2.viewer.mainact.MyLotteryAct;
import com.esun.rabbit2.viewer.mainact.OptionAct;
import com.esun.ui.R;
import com.esun.util.ViewerUtil;
import com.esun.util.log.EDebug;
import com.esun.util.magic.magic;

/**
 * @Title: MainAct.java
 * @Package com.esun.ui
 * @Description: (主ActivityGroup,承载其他Activity)
 * @author City jiangsy@500wan.com
 * @date 2011-5-13 下午05:19:25 copy right 深圳市易讯天空网络技术有限公司
 */
public class MainAct extends ActivityGroup implements OnClickListener {

	/** 升级地址 */
	private String strUpdateURL;

	// added by kuroky
	private static final String EVENT = "event";
	private static final String PRODUCT = "product";
	private static final String MAGIC_NUM = "serial";
	private static final String QUIT_INFO = "Rabbit Quit!!";

	public static final int LOTTERY_NOTIFICATION = 1;

	public static final int REGISTER_NOTIFICATION = 2;

	public static final int ACTIVITY_NOTIFICATION = 3;

	public static final int LOTTERY_HALL_ACTIVITY = 1;

	public static final int HEMAI_CENTER_ACTIVITY = 2;

	public static final int LOTTERY_INFO_ACTIVITY = 3;

	public static final int MY_LOTTERY_ACTIVITY = 4;

	public static final int OPTION_ACTIVITY = 5;

	private LoadingInfo loadingInfo;

	private int currentChildIndex = 1;

	private Dialog dialogLock;

	private RabbitApplication application;
	private RelativeLayout linearLotteryHall, linearHeMainCenter, linearLotteryInfo, linearMyLottery, linearOption;
	private ImageView imgLotteryHall, imgHeMainCenter, imgLotteryRecord, imgMyLottery, imgOption;
	private TextView tvLotteryHall, tvHeMainCenter, tvLotteryRecord, tvMyLottery, tvOption;
	private ImageView ivLotteryHallNotification, ivHeMainCenterNotification, ivLotteryRecordNotification, ivMyLotteryNotification, ivOptionNotification;
	private LinearLayout linearChildContainer;

	private NotificationHandler mNotificationHandler = new NotificationHandler();

	private MainNotificationReceiver mMainNotificationReceiver;

	/** 设备信息收集通信接口 */
	private DeviceInfoCollectCommunicater infoCommunicater;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		EDebug.o(this, Config.CRYSTRING);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		application = (RabbitApplication) getApplication();
		init();
		updateState();
		isAutoLoginSucceed();
		// 信息收集线程
		infoCollectThread();
		registerNotificationRecevier();
	}

	/**
	 * @title registerNotificationRecevier
	 * @description
	 */
	private void registerNotificationRecevier() {
		mMainNotificationReceiver = new MainNotificationReceiver(mNotificationHandler);
		IntentFilter filter = new IntentFilter();
		filter.addAction(Constants.ACTION_SHOW_NOTIFICATION);
		registerReceiver(mMainNotificationReceiver, filter);

	}

	private void unregisterNotificationRecevier() {
		unregisterReceiver(mMainNotificationReceiver);
	}

	/**
	 * @Title: updateState
	 * @Description: 检测是否需要升级
	 * @param: @param state
	 * @param: @param msg
	 * @param: @param url 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void updateState() {

		String updateState = loadingInfo.getIsupdate();

		if (updateState != null && !updateState.equals(Config.NULLMARK)) {
			if (updateState.equals(Config.NUM1)) {
				String updateNote = loadingInfo.getUpdatenotes();
				if (updateNote == null || updateNote.equals(Config.NULLMARK)) {
					updateNote = Config.NULLMARK;
				} else {
					updateNote = updateNote.replace('$', '\n');
				}
				strUpdateURL = loadingInfo.getUpdateurl();
				showUpdateDialog(Language.UPDATE_DIALOG_TITLE, Language.UPDATE_DIALOG_CONTENT + '\n' + updateNote, updateOnClickListener);
			}
		}
	}

	/**
	 * @Title: isAutoLogin
	 * @Description: 判断自动登录是否成功
	 * @param: @param state 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void isAutoLoginSucceed() {

		String autoLoginState = loadingInfo.getState();

		if (autoLoginState != null && !autoLoginState.equals(Config.NULLMARK)) {
			if (autoLoginState.equals(Config.COMMUNICATED_SUCCEED)) {
				EDebug.o(MainAct.this, "自动登录成功");
			} else if (autoLoginState.equals(Config.LOGIN_LOCKED)) {
				EDebug.o(MainAct.this, "自动登录锁定");
				String lockType = loadingInfo.getResultcode();
				if (lockType.equals(Config.NUM1)) {
					showLockDialog();
				} else if (lockType.equals(Config.NUM2) || lockType.equals(Config.NUM3)) {
					ViewerUtil.showTipDialog(MainAct.this, Language.MSG_IPLOCKED, false);
				}
			} else {
				EDebug.o(MainAct.this, "自动登录失败");
			}
		}

	}

	/**
	 * @Title: showLockDialog
	 * @Description: 提示登陆锁定，引导解锁
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void showLockDialog() {
		if (dialogLock == null) {
			dialogLock = new Dialog(this, R.style.dialog);
		}
		dialogLock.getWindow().setContentView(R.layout.viewerutil_dialog_usernamelocked);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.viewerutildialogusernamelocked_btn_cancel:
					dialogLock.dismiss();
					break;

				case R.id.viewerutildialogusernamelocked_btn_submit:
					Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Config.URL_UNLOCK));
					startActivity(intent);
					dialogLock.dismiss();
					break;

				default:
					break;
				}
			}
		};
		((Button) dialogLock.getWindow().findViewById(R.id.viewerutildialogusernamelocked_btn_cancel)).setOnClickListener(listener);
		((Button) dialogLock.getWindow().findViewById(R.id.viewerutildialogusernamelocked_btn_submit)).setOnClickListener(listener);
		((TextView) dialogLock.getWindow().findViewById(R.id.viewerutildialogusernamelocked_tv_msg)).setText(Language.MSG_ACCOUNTLOCKED);
		dialogLock.show();
	}

	private void init() {
		loadingInfo = LoadingInfo.getInstance();

		linearChildContainer = (LinearLayout) findViewById(R.id.main_linear_childContainer);
		/** ======================================================================== */

		linearLotteryHall = (RelativeLayout) MainAct.this.findViewById(R.id.main_linear_lotteryhall);
		linearLotteryHall.setOnClickListener(this);
		linearHeMainCenter = (RelativeLayout) MainAct.this.findViewById(R.id.main_linear_heimaicenter);
		linearHeMainCenter.setOnClickListener(this);
		linearLotteryInfo = (RelativeLayout) MainAct.this.findViewById(R.id.main_linear_lotteryInfo);
		linearLotteryInfo.setOnClickListener(this);
		linearMyLottery = (RelativeLayout) MainAct.this.findViewById(R.id.main_linear_mylottery);
		linearMyLottery.setOnClickListener(this);
		linearOption = (RelativeLayout) MainAct.this.findViewById(R.id.main_linear_option);
		linearOption.setOnClickListener(this);

		imgLotteryHall = (ImageView) findViewById(R.id.main_img_lotteryhall);
		imgHeMainCenter = (ImageView) findViewById(R.id.main_img_hemaicenter);
		imgLotteryRecord = (ImageView) findViewById(R.id.main_img_lotteryrecord);
		imgMyLottery = (ImageView) findViewById(R.id.main_img_mylottery);
		imgOption = (ImageView) findViewById(R.id.main_img_option);

		tvLotteryHall = (TextView) findViewById(R.id.main_tv_lotteryhall);
		tvHeMainCenter = (TextView) findViewById(R.id.main_tv_hemaicenter);
		tvLotteryRecord = (TextView) findViewById(R.id.main_tv_lotteryrecord);
		tvMyLottery = (TextView) findViewById(R.id.main_tv_mylottery);
		tvOption = (TextView) findViewById(R.id.main_tv_option);

		ivLotteryHallNotification = (ImageView) findViewById(R.id.lotteryhall_notification_icon);
		ivHeMainCenterNotification = (ImageView) findViewById(R.id.heimaicenter_notification_icon);
		ivLotteryRecordNotification = (ImageView) findViewById(R.id.lotteryrecord_notification_icon);
		ivMyLotteryNotification = (ImageView) findViewById(R.id.mylottery_notification_icon);
		ivOptionNotification = (ImageView) findViewById(R.id.option_notification_icon);

		// 根据application中的标识设置push通知的图标
		if (application.isReceivedActivityNotification() && Config.NOTIFICATION_ICON_DISPLAY_STATE) {
			ivLotteryHallNotification.setVisibility(View.VISIBLE);
		}
		if (application.isReceivedLotteryNotification() && Config.NOTIFICATION_ICON_DISPLAY_STATE) {
			ivLotteryRecordNotification.setVisibility(View.VISIBLE);
		}
		if (application.isReceivedRegisteNotification() && Config.NOTIFICATION_ICON_DISPLAY_STATE) {
			ivOptionNotification.setVisibility(View.VISIBLE);
		}

		application.closeSetNotification();
		setChildActivity(LOTTERY_HALL_ACTIVITY);
		/** ======================================================================== */

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// 这里放捕获按键处理事件
			showQuitDialog();
			return true;
		} else
			return super.onKeyDown(keyCode, event);
		// 除了捕获你想要的返回键之外，其余的应该交给他的父类去处理
	}

	private Dialog quitDialog;
	private Button btnDialogSubmit;
	private Button btnDialogcancel;
	private TextView tvDialogMsg;

	private void showQuitDialog() {
		quitDialog = new Dialog(this, R.style.dialog);
		quitDialog.getWindow().setContentView(R.layout.dialog_quit);

		tvDialogMsg = (TextView) quitDialog.getWindow().findViewById(R.id.dialogquit_tv_msg);
		tvDialogMsg.setText(Language.MSG_QUITDIALOG);
		btnDialogcancel = (Button) quitDialog.getWindow().findViewById(R.id.dialogquit_btn_cancel);
		btnDialogcancel.setOnClickListener(MainAct.this);
		btnDialogSubmit = (Button) quitDialog.getWindow().findViewById(R.id.dialogquit_btn_submit);
		btnDialogSubmit.setOnClickListener(this);

		quitDialog.show();
	}

	@Override
	protected void onDestroy() {
		application.closeSetNotification();
		application.openSetNotification();
		unregisterNotificationRecevier();
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	@Override
	protected void onResume() {
		super.onResume();
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());

		if (UserInfo.getUserInfo().isRebuy()) {
			UserInfo.getUserInfo().setRebuy(false);
			setChildActivity(LOTTERY_HALL_ACTIVITY);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.dialogquit_btn_submit:
			// 退出前通信
			notifyServer(MainAct.this);
			android.os.Process.killProcess(android.os.Process.myPid());
			break;

		case R.id.dialogquit_btn_cancel:
			quitDialog.dismiss();
			break;

		case R.id.main_linear_lotteryhall:

			clearCurrentNotificationIcon();
			this.ivLotteryHallNotification.setVisibility(View.INVISIBLE);
			setChildActivity(LOTTERY_HALL_ACTIVITY);

			break;

		case R.id.main_linear_heimaicenter:

			clearCurrentNotificationIcon();
			this.ivHeMainCenterNotification.setVisibility(View.INVISIBLE);
			setChildActivity(HEMAI_CENTER_ACTIVITY);

			break;

		case R.id.main_linear_lotteryInfo:

			clearCurrentNotificationIcon();
			this.ivLotteryRecordNotification.setVisibility(View.INVISIBLE);
			setChildActivity(LOTTERY_INFO_ACTIVITY);

			break;

		case R.id.main_linear_mylottery:
			clearCurrentNotificationIcon();
			this.ivMyLotteryNotification.setVisibility(View.INVISIBLE);
			setChildActivity(MY_LOTTERY_ACTIVITY);

			break;

		case R.id.main_linear_option:
			clearCurrentNotificationIcon();
			this.ivOptionNotification.setVisibility(View.INVISIBLE);
			setChildActivity(OPTION_ACTIVITY);

			break;

		default:

			break;
		}

	}

	/**
	 * @title clearNotificationIcon
	 * @description
	 */
	private void clearCurrentNotificationIcon() {

		switch (currentChildIndex) {

		case LOTTERY_HALL_ACTIVITY:
			this.ivLotteryHallNotification.setVisibility(View.INVISIBLE);
			break;

		case HEMAI_CENTER_ACTIVITY:
			break;

		case LOTTERY_INFO_ACTIVITY:
			this.ivLotteryRecordNotification.setVisibility(View.INVISIBLE);
			break;

		case MY_LOTTERY_ACTIVITY:
			break;

		case OPTION_ACTIVITY:
			this.ivOptionNotification.setVisibility(View.INVISIBLE);
			break;

		default:
			break;
		}

	}

	private void changeImage(boolean flag, RelativeLayout linear, ImageView img, TextView tv, Drawable drawable) {

		if (flag) {
			linear.setBackgroundDrawable(getResources().getDrawable(R.drawable.gcdt_btn_focused_43x47));
			tv.setVisibility(View.VISIBLE);
		} else {
			linear.setBackgroundDrawable(getResources().getDrawable(R.drawable.m_menu_bg_unpressed_icon));
			tv.setVisibility(View.GONE);
		}
		img.setBackgroundDrawable(drawable);

	}

	private UpdateOnClickListener updateOnClickListener = new UpdateOnClickListener();

	private class UpdateOnClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {

			switch (v.getId()) {

			case R.id.dialog_update_btn_cancel:

				updatedialog.dismiss();

				break;

			case R.id.dialog_update_btn_submit:

				if (strUpdateURL == null || strUpdateURL.equals(Config.NULLMARK)) {
					EDebug.o(this, "升级地址不可用");
					Toast.makeText(MainAct.this, Language.MSG_UPDATE_URL_NOTWORK, Toast.LENGTH_SHORT).show();
				} else {
					Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strUpdateURL));
					startActivity(intent);
					updatedialog.dismiss();
				}

				break;

			}
		}
	}

	private Dialog updatedialog;
	private Button btnUpdateDialogSubmit;
	private Button btnUpdateDialogCancel;
	private TextView tvUpdateDialogMsg;
	private TextView tvUpdateTitleMsg;

	private void showUpdateDialog(String title, String msg, OnClickListener l) {
		updatedialog = new Dialog(this, R.style.dialog);
		updatedialog.getWindow().setContentView(R.layout.dialog_update);

		tvUpdateTitleMsg = (TextView) updatedialog.getWindow().findViewById(R.id.dialog_update_tv_title);
		tvUpdateTitleMsg.setText(title);
		tvUpdateDialogMsg = (TextView) updatedialog.getWindow().findViewById(R.id.dialog_update_tv_msg);
		tvUpdateDialogMsg.setText(msg);
		btnUpdateDialogCancel = (Button) updatedialog.getWindow().findViewById(R.id.dialog_update_btn_cancel);
		btnUpdateDialogCancel.setOnClickListener(l);
		btnUpdateDialogSubmit = (Button) updatedialog.getWindow().findViewById(R.id.dialog_update_btn_submit);
		btnUpdateDialogSubmit.setOnClickListener(l);
		updatedialog.setOnDismissListener(new OnDismissListener() {

			@Override
			public void onDismiss(DialogInterface dialog) {
				// 如果需要强制升级，则退出客户端
				String isMustUpdate = loadingInfo.getIsmustupdate();
				if (isMustUpdate != null && !isMustUpdate.equals(Config.NULLMARK)) {
					if (isMustUpdate.equals(Config.NUM1)) {
						// 退出前通信
						notifyServer(MainAct.this);
						android.os.Process.killProcess(android.os.Process.myPid());
					}
				}
			}
		});
		updatedialog.show();
	}

	public static void notifyServer(Context con) {

		postMsg(con);
	}

	private static void postMsg(final Context con) {
		new Thread() {

			@Override
			public void run() {
				super.run();

				String magicNum;

				if (UserInfo.getUserInfo().getWlanMac() == Config.NULLMARK) {
					magic.setContext(con);
					magicNum = magic.getMagicNum();
				} else {
					magicNum = UserInfo.getUserInfo().getWlanMac();
				}

				HttpPost httpRequest = new HttpPost(Config.MAGIC_ADD);

				List<NameValuePair> params = new ArrayList<NameValuePair>();

				try {

					EDebug.o(QUIT_INFO, "============================ Rabbit Quit Info ======================================");

					params.add(new BasicNameValuePair(EVENT, "4"));

					params.add(new BasicNameValuePair(PRODUCT, "rabbit"));
					EDebug.o(QUIT_INFO, PRODUCT + " : " + "rabbit");

					params.add(new BasicNameValuePair(MAGIC_NUM, magicNum));
					EDebug.o(QUIT_INFO, MAGIC_NUM + " : " + magicNum);

					EDebug.o(QUIT_INFO, "============================ Rabbit Quit Info ======================================");

					httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

					HttpParams httpParameters = new BasicHttpParams();

					HttpConnectionParams.setConnectionTimeout(httpParameters, 1000);

					HttpConnectionParams.setSoTimeout(httpParameters, 1000);

					new DefaultHttpClient(httpParameters).execute(httpRequest);

				} catch (Exception e) {
				}
			}

		}.start();

	}

	class NotificationHandler extends Handler {

		@Override
		public void handleMessage(Message msg) {
			if (Config.NOTIFICATION_ICON_DISPLAY_STATE) {
				switch (msg.what) {

				case LOTTERY_NOTIFICATION:
					ivLotteryRecordNotification.setVisibility(View.VISIBLE);
					break;

				case REGISTER_NOTIFICATION:
					ivOptionNotification.setVisibility(View.VISIBLE);
					break;

				case ACTIVITY_NOTIFICATION:
					ivLotteryHallNotification.setVisibility(View.VISIBLE);
					break;

				default:
					break;
				}
			}
			super.handleMessage(msg);
		}

	}

	/**
	 * @Title: infoCollectThread
	 * @Description: 设备信息收集通讯线程
	 */
	private void infoCollectThread() {
		new Thread() {

			@Override
			public void run() {
				super.run();
				try {

					// 获取其他运行时间信息
					String channel = DistributionChannels.QUDAO;
					String version = UserInfo.getUserInfo().getCurrentVersion();
					magic.setContext(MainAct.this);
					String sysVersion = magic.getPhoneRelease();
					String screenReso = magic.getScreenInfo();
					String serial = magic.getMagicNum();
					String nettype = magic.getNetType();
					String[] locationInfo = magic.getLocationInfo(nettype);
					String name = UserInfo.getUserInfo().getUserName();
					String pwd = UserInfo.getUserInfo().getUserPwd();
					String userIMEI;

					if (infoCommunicater == null) {
						infoCommunicater = new DeviceInfoCollectCommunicater();
					}

					SharedPreferences sharedPre = MainAct.this.getSharedPreferences(Config.CLIENT_PREFERENCES, Context.MODE_PRIVATE);
					userIMEI = sharedPre.getString(Constants.DEVICE_ID, Config.DEFAULT_LEAGUAGE_NUM);
					String IMEI = magic.getIMEI(MainAct.this);

					boolean isSucceed = infoCommunicater.isSendSucceed(name, pwd, channel, version, sysVersion, screenReso, serial, userIMEI, nettype, locationInfo[2], locationInfo[0],
							locationInfo[1], IMEI);

					if (isSucceed) {
						EDebug.o(this, "信息收集成功");
					} else {
						EDebug.o(this, "信息收集失败");
					}

				} catch (Exception e) {
					EDebug.o(this, "信息收集异常" + e.getStackTrace().toString());
				}
			}

		}.start();
	}

	public void setChildActivity(int index) {

		currentChildIndex = index;

		switch (index) {

		case LOTTERY_HALL_ACTIVITY:

			linearChildContainer.removeAllViews();
			linearChildContainer.addView(getLocalActivityManager().startActivity("lotteryhall", new Intent(MainAct.this, LotteryHallAct.class)).getDecorView());

			changeImage(true, linearLotteryHall, imgLotteryHall, tvLotteryHall, getResources().getDrawable(R.drawable.gcdt_icon_home_focused_68x47));
			changeImage(false, linearHeMainCenter, imgHeMainCenter, tvHeMainCenter, getResources().getDrawable(R.drawable.button_default_buytogether_btcenter_64x47));
			changeImage(false, linearLotteryInfo, imgLotteryRecord, tvLotteryRecord, getResources().getDrawable(R.drawable.gcdt_icon_volume_19x22));
			changeImage(false, linearMyLottery, imgMyLottery, tvMyLottery, getResources().getDrawable(R.drawable.gcdt_icon_user_21x22));
			changeImage(false, linearOption, imgOption, tvOption, getResources().getDrawable(R.drawable.gcdt_icon_set_23x22));

			break;

		case HEMAI_CENTER_ACTIVITY:

			linearChildContainer.removeAllViews();
			linearChildContainer.addView(getLocalActivityManager().startActivity("hemaicenter", new Intent(MainAct.this, HemaiCenterAgp.class)).getDecorView());

			changeImage(false, linearLotteryHall, imgLotteryHall, tvLotteryHall, getResources().getDrawable(R.drawable.gcdt_icon_home_24x21));
			changeImage(true, linearHeMainCenter, imgHeMainCenter, tvHeMainCenter, getResources().getDrawable(R.drawable.button_focus_buytogether_btcenter_64x47));
			changeImage(false, linearLotteryInfo, imgLotteryRecord, tvLotteryRecord, getResources().getDrawable(R.drawable.gcdt_icon_volume_19x22));
			changeImage(false, linearMyLottery, imgMyLottery, tvMyLottery, getResources().getDrawable(R.drawable.gcdt_icon_user_21x22));
			changeImage(false, linearOption, imgOption, tvOption, getResources().getDrawable(R.drawable.gcdt_icon_set_23x22));

			break;

		case LOTTERY_INFO_ACTIVITY:

			linearChildContainer.removeAllViews();
			linearChildContainer.addView(getLocalActivityManager().startActivity("lotteryinfo", new Intent(MainAct.this, LotteryInfoAct.class)).getDecorView());

			changeImage(false, linearLotteryHall, imgLotteryHall, tvLotteryHall, getResources().getDrawable(R.drawable.gcdt_icon_home_24x21));
			changeImage(false, linearHeMainCenter, imgHeMainCenter, tvHeMainCenter, getResources().getDrawable(R.drawable.button_default_buytogether_btcenter_64x47));
			changeImage(true, linearLotteryInfo, imgLotteryRecord, tvLotteryRecord, getResources().getDrawable(R.drawable.gcdt_icon_volume_focused_68x47));
			changeImage(false, linearMyLottery, imgMyLottery, tvMyLottery, getResources().getDrawable(R.drawable.gcdt_icon_user_21x22));
			changeImage(false, linearOption, imgOption, tvOption, getResources().getDrawable(R.drawable.gcdt_icon_set_23x22));

			break;

		case MY_LOTTERY_ACTIVITY:

			linearChildContainer.removeAllViews();
			linearChildContainer.addView(getLocalActivityManager().startActivity("mylottery", new Intent(MainAct.this, MyLotteryAct.class)).getDecorView());

			changeImage(false, linearLotteryHall, imgLotteryHall, tvLotteryHall, getResources().getDrawable(R.drawable.gcdt_icon_home_24x21));
			changeImage(false, linearHeMainCenter, imgHeMainCenter, tvHeMainCenter, getResources().getDrawable(R.drawable.button_default_buytogether_btcenter_64x47));
			changeImage(false, linearLotteryInfo, imgLotteryRecord, tvLotteryRecord, getResources().getDrawable(R.drawable.gcdt_icon_volume_19x22));
			changeImage(true, linearMyLottery, imgMyLottery, tvMyLottery, getResources().getDrawable(R.drawable.gcdt_icon_user_focused_68x47));
			changeImage(false, linearOption, imgOption, tvOption, getResources().getDrawable(R.drawable.gcdt_icon_set_23x22));

			break;

		case OPTION_ACTIVITY:

			linearChildContainer.removeAllViews();
			linearChildContainer.addView(getLocalActivityManager().startActivity("option", new Intent(MainAct.this, OptionAct.class)).getDecorView());

			changeImage(false, linearLotteryHall, imgLotteryHall, tvLotteryHall, getResources().getDrawable(R.drawable.gcdt_icon_home_24x21));
			changeImage(false, linearHeMainCenter, imgHeMainCenter, tvHeMainCenter, getResources().getDrawable(R.drawable.button_default_buytogether_btcenter_64x47));
			changeImage(false, linearLotteryInfo, imgLotteryRecord, tvLotteryRecord, getResources().getDrawable(R.drawable.gcdt_icon_volume_19x22));
			changeImage(false, linearMyLottery, imgMyLottery, tvMyLottery, getResources().getDrawable(R.drawable.gcdt_icon_user_21x22));
			changeImage(true, linearOption, imgOption, tvOption, getResources().getDrawable(R.drawable.gcdt_icon_set_focused_68x47));

			break;

		default:

			break;

		}

	}

}
